package main.strategy;

import http.util.PrintUtil;
import main.robClass;
import mysql.MysqlUtil;
import user.IUser;
import java.util.HashMap;
import java.util.Scanner;

//模板方法
//交给子类实现具体
/*选课**/
public abstract class SelectCourseListStartegy implements RobStrategy {

    @Override
    public void execute(IUser user) throws Exception {
        robClass.logger.info("=========================================选择课程=========================================");
        robClass.logger.info(user);
        if (user != null) {
            try {
                user.login();
            } catch (Exception e) {
                try {
                    Thread.sleep(2000); //2秒后重试
                    PrintUtil.printError(user, Thread.currentThread());
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
                e.printStackTrace();
            }
            /**应该根据传入的子继承策略进行*/

            //PERobber peRobber = new PERobber(user);
            //peRobber.syncSearchClasses().entrySet().stream().forEach(x -> robClass.logger.info("课名：" + x.getKey() + "  id:" + x.getValue()));
            Scanner keyBoardInput = new Scanner(System.in, "UTF-8");
                robClass.logger.info("=========================================选择抢课模式=========================================");
                robClass.logger.info("1.列表抢课[单/多] - 选择我将获取且显示课程列表");
                robClass.logger.info("2.随机抢课");
                robClass.logger.info("3.全部抢课");
                if (keyBoardInput.hasNextInt()) {
                    switch (keyBoardInput.nextInt()) {
                        case 1:
                            robClass.logger.info("=========================================列表抢课模式=========================================");
                            robClass.logger.info("请输入要抢课的id");
                            robListCourse(user);
                            robClass.logger.info("设置成功: 列表抢课模式");
                            break;
                        case 2:
                            robClass.logger.info("=========================================随机抢课模式=========================================");
                            //    robRandomCourse(user,classSelects);
                            robClass.logger.info("设置成功: 随机抢课模式");
                            break;
                        case 3:
                            robClass.logger.info("=========================================全部抢课模式=========================================");
                            //  robAllCourse(user,classSelects);
                            robClass.logger.info("设置成功: 全部抢课模式");
                            break;
                    }
                }
                MysqlUtil.updateUser(user);
//            user.outPutRobs();

        } else {
            robClass.logger.info("账号不存在!");
        }


    }


    protected abstract void robListCourse(IUser user) throws Exception;

    protected abstract void robRandomCourse(IUser user, HashMap<String, String> classSelects);

    protected abstract void robAllCourse(IUser user, HashMap<String, String> classSelects);

}
